using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.MedicalDataInterf;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model.DataInterfaces.CRMDataInterf;
using ShivamEMR.Model.DataInterfaces.CompanyDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class PatientTestController : Controller
    {
		private readonly ITestRepository testRepository;
		private readonly IPatientTestPictureRepository patienttestpictureRepository;
		private readonly IPatientRepository patientRepository;
		private readonly IVenueRepository venueRepository;
		private readonly IEmployeeRepository employeeRepository;
		private readonly IPatientTestRepository patienttestRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PatientTestController()// : this(new TestRepository(), new PatientTestPictureRepository(), new PatientRepository(), new VenueRepository(), new EmployeeRepository(), new PatientTestRepository())
        {
            this.testRepository = Registry.RepositoryFactory.GetTestRepository();
            this.patienttestpictureRepository = Registry.RepositoryFactory.GetPatientTestPictureRepository();
            this.patientRepository = Registry.RepositoryFactory.GetPatientRepository();
            this.venueRepository = Registry.RepositoryFactory.GetVenueRepository();
            this.employeeRepository = Registry.RepositoryFactory.GetEmployeeRepository();
            this.patienttestRepository =Registry.RepositoryFactory.GetPatientTestRepository();
        }

        public PatientTestController(ITestRepository testRepository, IPatientTestPictureRepository patienttestpictureRepository, IPatientRepository patientRepository, IVenueRepository venueRepository, IEmployeeRepository employeeRepository, IPatientTestRepository patienttestRepository)
        {
			this.testRepository = testRepository;
			this.patienttestpictureRepository = patienttestpictureRepository;
			this.patientRepository = patientRepository;
			this.venueRepository = venueRepository;
			this.employeeRepository = employeeRepository;
			this.patienttestRepository = patienttestRepository;
        }

        //
        // GET: /PatientTest/

        public ViewResult Index()
        {
            return View(patienttestRepository.All);//Including(patienttest => patienttest.Test, patienttest => patienttest.Picture, patienttest => patienttest.Patient, patienttest => patienttest.Venue, patienttest => patienttest.Technician, patienttest => patienttest.ResultPictures));
        }

        //
        // GET: /PatientTest/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(patienttestRepository.Find(id));
        }

        //
        // GET: /PatientTest/Create

        public ActionResult Create()
        {
			ViewBag.PossibleTests = testRepository.All;
			ViewBag.PossiblePictures = patienttestpictureRepository.All;
			ViewBag.PossiblePatients = patientRepository.All;
			ViewBag.PossibleVenues = venueRepository.All;
			ViewBag.PossibleTechnicians = employeeRepository.All;
            return View();
        } 

        //
        // POST: /PatientTest/Create

        [HttpPost]
        public ActionResult Create(PatientTest patienttest)
        {
            if (ModelState.IsValid) {
                patienttestRepository.Create(patienttest);
                patienttestRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleTests = testRepository.All;
				ViewBag.PossiblePictures = patienttestpictureRepository.All;
				ViewBag.PossiblePatients = patientRepository.All;
				ViewBag.PossibleVenues = venueRepository.All;
				ViewBag.PossibleTechnicians = employeeRepository.All;
				return View();
			}
        }
        
        //
        // GET: /PatientTest/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleTests = testRepository.All;
			ViewBag.PossiblePictures = patienttestpictureRepository.All;
			ViewBag.PossiblePatients = patientRepository.All;
			ViewBag.PossibleVenues = venueRepository.All;
			ViewBag.PossibleTechnicians = employeeRepository.All;
             return View(patienttestRepository.Find(id));
        }

        //
        // POST: /PatientTest/Edit/5

        [HttpPost]
        public ActionResult Edit(PatientTest patienttest)
        {
            if (ModelState.IsValid) {
                patienttestRepository.Update(patienttest);
                patienttestRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleTests = testRepository.All;
				ViewBag.PossiblePictures = patienttestpictureRepository.All;
				ViewBag.PossiblePatients = patientRepository.All;
				ViewBag.PossibleVenues = venueRepository.All;
				ViewBag.PossibleTechnicians = employeeRepository.All;
				return View();
			}
        }

        //
        // GET: /PatientTest/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(patienttestRepository.Find(id));
        }

        //
        // POST: /PatientTest/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var pt = patienttestRepository.Find(id);
            patienttestRepository.Delete(pt);
            patienttestRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

